package com.gs.synedocket.adapter;

import android.content.Context;

import com.gs.synedocket.R;
import com.gs.synedocket.adapter.base.BaseAdapter;
import com.gs.synedocket.adapter.base.BaseViewHolder;
import com.gs.synedocket.db.dto.DocketDto;
import com.gs.synedocket.db.dto.DocketSiteDto;
import com.gs.synedocket.db.dto.ShortDto;
import com.gs.synedocket.util.DateUtil;

import java.util.List;

public class DocketLogAdapter extends BaseAdapter<DocketDto> {
    public DocketLogAdapter(Context context, List<DocketDto> list, int layoutId) {
        super(context, list, layoutId);
    }

    @Override
    public void convert(BaseViewHolder holder, DocketDto item, int position) {
        holder.setDocketText(R.id.view_docket_no, item.getDocketNo() == null ? "" : item.getDocketNo());
        holder.setDocketText(R.id.view_date, DateUtil.DateTimeToStr(item.getBatchTime(), "yyyy-MM-dd HH:mm"));
        holder.setDocketText(R.id.view_quantity, item.getLoadQty() == null ? "" : item.getLoadQty() + "");
        if (item.getCustomer() != null) {
            ShortDto customer = item.getCustomer();
            holder.setDocketText(R.id.view_customer, customer.getName() == null ? "" : customer.getName());
        } else {
            holder.setDocketText(R.id.view_customer, "");
        }
        if (item.getSite() != null) {
            DocketSiteDto site = item.getSite();
            String siteName = site.getName();
            String extraAddress = item.getExtraAddress();
            String name = (siteName == null ? "" : siteName) + (extraAddress == null ? "" : " " + extraAddress);
            holder.setDocketText(R.id.view_site, name);
        } else {
            holder.setDocketText(R.id.view_site, "");
        }
    }
}
